﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using ThingPower.WeChat.MP.Entities;
using ThingPower.WeChat.MP.Entities.Request;
using ThingPower.WeChat.MP.MessageHandlers;

namespace WeChatDemo
{
    public class CustomMessageHandler : MessageHandler<CustomMessageContext>
    {
        public CustomMessageHandler(Stream inputStream, PostModel postModel)
            : base(inputStream, postModel)
        {
        }

        public override IResponseMessageBase DefaultResponseMessage(IRequestMessageBase requestMessage)
        {
            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            //设置默认响应消息
            responseMessage.Content = "The message is from DefaultResponseMessage.";
            return responseMessage;
        }

        //响应用户发送来的文本信息
        public override IResponseMessageBase OnTextRequest(RequestMessageText requestMessage)
        {
            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "您的OpenID是:" + requestMessage.FromUserName + "。\r\n您发送的文本信息:" + requestMessage.Content;
            return responseMessage;
        }

        //当用户关注时自动发送文本消息
        public override IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "Thank you so much.";
            return responseMessage;
        }

        //当用户取消关注时自动发送文本消息
        public override IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage)
        {
            var responseMessage = base.CreateResponseMessage<ResponseMessageText>();
            responseMessage.Content = "I am so sorry.";
            return responseMessage;
        }
    }
}